package thomas.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import thomas.web.entity.Resident;
import thomas.web.service.ResidentSevice;

//@RestController
@Controller
@RequestMapping("/resident/")
public class ResidentController {
	
	@Autowired
	private ResidentSevice residentSevice;
	
	@GetMapping("list")
	public String getResidents(){
		return "resident/residents";
	}
 
	@GetMapping("{username}")
	public String getResident(@PathVariable("username") String username, Model model){
		Resident resident = residentSevice.getResident(username);
		model.addAttribute(resident);
		return "resident/resident";
	}
	
	@GetMapping("{username}/edit")
	public String editResident(@PathVariable("username") String username, Model model){
		Resident resident = residentSevice.getResident(username);
		model.addAttribute(resident);
		model.addAttribute("edit", true);
		return "resident/resident";
	}
	
}
